/**
 * 防抖
 *
 * @param {Function} func
 * @param {Number} delay
 * @returns Function
 */
function debounce(func, delay = 1000) {
  let timer = null;
  return function () {
    let context = this;
    let args = arguments;
    if (timer !== null) {
      clearTimeout(timer);
    }
    timer = setTimeout(() => {
      func.apply(context, args);
    }, delay);
  };
}

export default debounce;
